package com.zlx.sharelive.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.example.zhouwei.library.CustomPopWindow;
import com.lzj.pass.dialog.PayPassDialog;
import com.lzj.pass.dialog.PayPassView;
import com.paradoxie.autoscrolltextview.VerticalTextview;
import com.zlx.module_base.base_api.res_data.BaseBean;
import com.zlx.module_base.base_api.res_data.DynamicListBean;
import com.zlx.module_base.base_api.res_data.DynamicOrderBody;
import com.zlx.module_base.base_api.res_data.DynamicsLabelBean;
import com.zlx.module_base.base_api.res_data.HomeRollAnnouncementBean;
import com.zlx.module_base.base_api.res_data.QueryByBean;
import com.zlx.module_base.base_api.util.ApiUtil;
import com.zlx.module_base.base_fg.BaseFg;
import com.zlx.module_base.base_util.SPUtil;
import com.zlx.module_network.api1.livedata.BaseObserver;
import com.zlx.module_network.api1.livedata.BaseObserverCallBack;
import com.zlx.module_network.bean.ApiResponse;
import com.zlx.sharelive.Constants;
import com.zlx.sharelive.R;
import com.zlx.sharelive.activity.CommunityAc;
import com.zlx.sharelive.activity.CommunityDetailsAc;
import com.zlx.sharelive.activity.ImageTextAc;
import com.zlx.sharelive.activity.TextAc;
import com.zlx.sharelive.adapter.CommonRecyclerViewAdapter;
import com.zlx.sharelive.adapter.CommonRecyclerViewHolder;
import com.zlx.sharelive.utils.GlideImgManager;
import com.zlx.sharelive.utils.NullTokenUtils;
import com.zlx.sharelive.utils.StringUt;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 社区
 */
public class CommunityFg extends BaseFg implements AMapLocationListener {


    @BindView(R.id.rv_topic)
    RecyclerView rv_topic;
    @BindView(R.id.rv_data)
    RecyclerView rv_data;
    @BindView(R.id.sw_layout)
    SwipeRefreshLayout sw_layout;
    @BindView(R.id.tv_attention)
    TextView tv_attention;
    @BindView(R.id.tv_recommend)
    TextView tv_recommend;
    @BindView(R.id.tv_same_city)
    TextView tv_same_city;
    @BindView(R.id.tv_feezone)
    TextView tv_feezone;
    @BindView(R.id.iv_attention)
    ImageView iv_attention;
    @BindView(R.id.iv_recommend)
    ImageView iv_recommend;
    @BindView(R.id.iv_same_city)
    ImageView iv_same_city;
    @BindView(R.id.iv_feezone)
    ImageView iv_feezone;
    @BindView(R.id.iv_community_dialog)
    ImageView iv_community_dialog;
    @BindView(R.id.tv_gonggao)
    VerticalTextview tv_gonggao;

    //声明mlocationClient对象
    public AMapLocationClient mlocationClient;
    //声明mLocationOption对象
    public AMapLocationClientOption mLocationOption = null;

    private String over;
    private int videoCount;
    private int page = 1;
    private String isSelf = "1", isTj = "", city = "", izFee = "";
    private List<TextView> textViewList;
    private List<ImageView> imageViewList;
    private List<DynamicListBean.InfoDTO> mList = new ArrayList<>();
    private CommonRecyclerViewAdapter<DynamicListBean.InfoDTO> mAdapter;
    private List<DynamicsLabelBean.InfoDTO> mTopicList = new ArrayList<>();
    private CommonRecyclerViewAdapter<DynamicsLabelBean.InfoDTO> mTopicAdapter;


    @Override
    protected int getLayoutId() {
        return R.layout.fg_community;
    }

    @Override
    protected void initViews() {
        super.initViews();

        dingwei();
        initTopic();
        getDynamicsLabel();
        initCommunity();
        page = 1;
        getDynamicList();
        initTextView();
        getHomeRollAnnouncement();
        queryById();

        sw_layout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getDynamicList();
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        getDynamicList();
    }

    /**
     * 根据用户id查询个人信息
     */
    private void queryById() {
        ApiUtil.getLoginApi().queryById(SPUtil.getToken(getContext()), (String) SPUtil.get(getContext(), Constants.SP_ID, ""))
                .observe(getViewLifecycleOwner(), new BaseObserver<>(new BaseObserverCallBack<ApiResponse<QueryByBean>>() {
                    @Override
                    public void onSuccess(ApiResponse<QueryByBean> data) {
                        if (null != data) {
                            if (null != data.getData()) {
                                if (data.getData().getCode() == 0) {
                                    if (null != data.getData().getInfo()) {
                                        if (data.getData().getInfo().size() > 0) {
                                            if (null != data.getData().getInfo().get(0).getResult()) {
                                                if (!StringUt.isEmpty(data.getData().getInfo().get(0).getResult().getVideoCount())) {
                                                    videoCount = Integer.valueOf(data.getData().getInfo().get(0).getResult().getVideoCount());
                                                    if (!StringUt.isEmpty(data.getData().getInfo().get(0).getResult().getMoney())) {
                                                        over = data.getData().getInfo().get(0).getResult().getMoney();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    NullTokenUtils.isNullToken(data.getData().getCode(), data.getData().getMsg());
                                }
                            }
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();

                    }
                }));
    }

    private void getHomeRollAnnouncement() {
        ApiUtil.getHomeApi().getHomeRollAnnouncement().observe(getViewLifecycleOwner(), new BaseObserver<>(new BaseObserverCallBack<ApiResponse<HomeRollAnnouncementBean>>() {
            @Override
            public void onSuccess(ApiResponse<HomeRollAnnouncementBean> data) {
                if (null != data) {
                    if (null != data.getData()) {
                        if (data.getData().getCode() == 0) {
                            if (tv_gonggao.getChildCount() < 2) {
                                ArrayList<String> titleList = new ArrayList<>();
                                for (int i = 0; i < data.getData().getInfo().size(); i++) {
                                    if (data.getData().getInfo().get(i).getType().equals("0")) {
                                        titleList.add(data.getData().getInfo().get(i).getNickName() + " 发布新的短视频");
                                    } else if (data.getData().getInfo().get(i).getType().equals("1")) {
                                        titleList.add(data.getData().getInfo().get(i).getNickName() + " 发布新的长视频");
                                    } else if (data.getData().getInfo().get(i).getType().equals("2")) {
                                        titleList.add(data.getData().getInfo().get(i).getNickName() + " 发布新的动态");
                                    } else if (data.getData().getInfo().get(i).getType().equals("3")) {
                                        titleList.add(data.getData().getInfo().get(i).getNickName() + " 发布新的文章");
                                    }
                                }
                                tv_gonggao.setTextList(titleList);//加入显示内容,集合类型
                                tv_gonggao.setTextStillTime(3000);//设置停留时长间隔
                                tv_gonggao.setAnimTime(300);//设置进入和退出的时间间隔
                                //对单条文字的点击监听
                                tv_gonggao.setOnItemClickListener(new VerticalTextview.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(int position) {
                                        // TO DO
                                    }
                                });
                                tv_gonggao.startAutoScroll();
                            }
                        } else {
                            NullTokenUtils.isNullToken(data.getData().getCode(), data.getData().getMsg());
                        }
                    }
                }

            }
        }));
    }

    /**
     * 动态标签列表
     */
    private void getDynamicsLabel() {
        ApiUtil.getHomeApi().getDynamicsLabel(SPUtil.getToken(getContext())).observe(getViewLifecycleOwner(), new BaseObserver<>(new BaseObserverCallBack<ApiResponse<DynamicsLabelBean>>() {
            @Override
            public void onSuccess(ApiResponse<DynamicsLabelBean> data) {
                if (null != data) {
                    if (null != data.getData()) {
                        if (data.getData().getCode() == 0) {
                            mTopicList.clear();
                            if (null != data) {
                                if (null != data.getData()) {
                                    mTopicList.addAll(data.getData().getInfo());
                                }
                            }
                            mTopicAdapter.notifyDataSetChanged();
                        } else {
                            NullTokenUtils.isNullToken(data.getData().getCode(), data.getData().getMsg());
                        }
                    }
                }
            }
        }));
    }

    private void dingwei() {
        AMapLocationClient.updatePrivacyShow(getContext(), true, true);
        AMapLocationClient.updatePrivacyAgree(getContext(), true);

        try {
            mlocationClient = new AMapLocationClient(getContext());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //初始化定位参数
        mLocationOption = new AMapLocationClientOption();
        //设置定位监听
        mlocationClient.setLocationListener(this);
        //设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //设置定位间隔,单位毫秒,默认为2000ms
//        mLocationOption.setInterval(2000);
        //设置定位参数
        mlocationClient.setLocationOption(mLocationOption);
        // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
        // 注意设置合适的定位时间的间隔（最小间隔支持为1000ms），并且在合适时间调用stopLocation()方法来取消定位请求
        // 在定位结束后，在合适的生命周期调用onDestroy()方法
        // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
//        //启动定位
//        mlocationClient.startLocation();
    }

    private void getDynamicList() {
        ApiUtil.getServiceApi().getDynamicList(SPUtil.getToken(getContext()),
                isSelf,
                "",
                city,
                izFee,
                "",
                String.valueOf(page),
                "",
                "",
                isTj,
                "",
                "").observe(getViewLifecycleOwner(), new BaseObserver<>(new BaseObserverCallBack<ApiResponse<DynamicListBean>>() {
            @Override
            public void onSuccess(ApiResponse<DynamicListBean> data) {
                sw_layout.setRefreshing(false);
                mList.clear();
                if (null != data) {
                    if (null != data.getData()) {
                        if (data.getData().getCode() == 0) {
                            if (null != data.getData().getInfo()) {
                                if (data.getData().getInfo().size() > 0) {
                                    for (int i = 0; i < data.getData().getInfo().size(); i++) {
                                        if (data.getData().getInfo().get(i).getCheckStatus().equals("1")) {
                                            mList.add(data.getData().getInfo().get(i));
                                        }
                                    }
                                }
                            }
                        } else {
                            NullTokenUtils.isNullToken(data.getData().getCode(), data.getData().getMsg());
                        }
                    }
                }
                mAdapter.notifyDataSetChanged();
            }
        }));
    }


    /**
     * 初始化按钮
     */
    private void initTextView() {
        textViewList = new ArrayList<>();
        textViewList.clear();
        imageViewList = new ArrayList<>();
        imageViewList.clear();

        textViewList.add(tv_attention);
        textViewList.add(tv_recommend);
        textViewList.add(tv_same_city);
        textViewList.add(tv_feezone);
        imageViewList.add(iv_attention);
        imageViewList.add(iv_recommend);
        imageViewList.add(iv_same_city);
        imageViewList.add(iv_feezone);
    }


    /**
     * 初始化热门话题数据
     */
    private void initTopic() {
        rv_topic.setLayoutManager(new GridLayoutManager(getContext(), 3));

        mTopicAdapter = new CommonRecyclerViewAdapter<DynamicsLabelBean.InfoDTO>(getContext(), mTopicList) {
            @Override
            public void convert(CommonRecyclerViewHolder holder, DynamicsLabelBean.InfoDTO entity, int position) {
                holder.setText(R.id.tv_topic_type, entity.getLabel());
            }

            @Override
            public int getLayoutViewId(int viewType) {
                return R.layout.item_topic;
            }
        };

        rv_topic.setAdapter(mTopicAdapter);

        mTopicAdapter.setOnRecyclerViewItemClickListener(new CommonRecyclerViewAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                startActivity(new Intent(getContext(), CommunityAc.class).putExtra("tag", mTopicList.get(position).getId())
                        .putExtra("title", mTopicList.get(position).getLabel()));
            }
        });
    }

    /**
     * 初始化社区分类列表数据
     */
    private void initCommunity() {
        rv_data.setLayoutManager(new LinearLayoutManager(getContext()));

        mAdapter = new CommonRecyclerViewAdapter<DynamicListBean.InfoDTO>(getContext(), mList) {
            @Override
            public void convert(CommonRecyclerViewHolder holder, DynamicListBean.InfoDTO entity, int position) {
                ImageView iv_community_head = holder.getView(R.id.iv_community_head);

                GlideImgManager.glideLoader(getContext(), entity.getAvatar(), iv_community_head, 0);

                holder.setText(R.id.tv_community_nickname, entity.getNickname());

                ImageView tv_yin = holder.getView(R.id.tv_yin);//阴影 判断是否是收费的

                if (!StringUt.isEmpty(entity.getIzFee())) {
                    if (entity.getIzFee().equals("1")) {
                        tv_yin.setVisibility(View.VISIBLE);
                        ((ImageView) holder.getView(R.id.iv_reward_img)).setVisibility(View.VISIBLE);
                    } else {
                        tv_yin.setVisibility(View.GONE);
                        ((ImageView) holder.getView(R.id.iv_reward_img)).setVisibility(View.GONE);
                    }
                } else {
                    tv_yin.setVisibility(View.GONE);
                }

                ImageView iv_community_vip = holder.getView(R.id.iv_community_vip);
                ImageView iv_community_goddess = holder.getView(R.id.iv_community_goddess);

                holder.setText(R.id.tv_reward_number, entity.getReword());

                if (!StringUt.isEmpty(entity.getIsvip())) {
                    if (entity.getIsvip().equals("2")) {
                        iv_community_vip.setVisibility(View.GONE);
                    } else {
                        iv_community_vip.setVisibility(View.VISIBLE);
                    }
                }

                if (!StringUt.isEmpty(entity.getAuthentication())) {
                    if (entity.getIsvip().equals("2")) {
                        iv_community_goddess.setVisibility(View.GONE);
                    } else {
                        iv_community_goddess.setVisibility(View.VISIBLE);
                    }
                }

                if (entity.getIsDz().equals("1")) {
                    ((ImageView) holder.getView(R.id.iv_fabulous_img)).setImageResource(R.mipmap.fabulous_img_true);
                } else {
                    ((ImageView) holder.getView(R.id.iv_fabulous_img)).setImageResource(R.mipmap.fabulous_img2);
                }

                holder.setText(R.id.tv_community_address, entity.getCity());
                holder.setText(R.id.tv_community_text_title, entity.getTitle());
                holder.setText(R.id.tv_community_text_content, entity.getText());
                holder.setText(R.id.tv_share_number, entity.getShares());
                holder.setText(R.id.tv_fabulous_number, entity.getLikes());
                holder.setText(R.id.tv_comment_number, entity.getComments());

                holder.setText(R.id.tv_community_time, entity.getDatetime());

                List<String> mImageList = new ArrayList<>();
                if (!StringUt.isEmpty(entity.getThumbs())) {
                    mImageList.add(entity.getThumbs());
                }
                if (!StringUt.isEmpty(entity.getThumb2())) {
                    mImageList.add(entity.getThumb2());
                }
                if (!StringUt.isEmpty(entity.getThumb3())) {
                    mImageList.add(entity.getThumb3());
                }
                if (!StringUt.isEmpty(entity.getThumb4())) {
                    mImageList.add(entity.getThumb4());
                }
                if (!StringUt.isEmpty(entity.getThumb5())) {
                    mImageList.add(entity.getThumb5());
                }
                if (!StringUt.isEmpty(entity.getThumb6())) {
                    mImageList.add(entity.getThumb6());
                }
                if (!StringUt.isEmpty(entity.getThumb7())) {
                    mImageList.add(entity.getThumb7());
                }
                if (!StringUt.isEmpty(entity.getThumb8())) {
                    mImageList.add(entity.getThumb8());
                }
                if (!StringUt.isEmpty(entity.getThumb9())) {
                    mImageList.add(entity.getThumb9());
                }

                RecyclerView rv_community_image = holder.getView(R.id.rv_community_image);

                rv_community_image.setLayoutManager(new GridLayoutManager(getContext(), 4));

                CommonRecyclerViewAdapter<String> mImageAdapter = new CommonRecyclerViewAdapter<String>(getContext(), mImageList) {
                    @Override
                    public void convert(CommonRecyclerViewHolder holder, String entity, int position1) {
                        FrameLayout fl_yin = holder.getView(R.id.fl_yin);

                        if (!StringUt.isEmpty(mList.get(position).getIzFee())) {
                            if (mList.get(position).getIzFee().equals("1")) {
                                fl_yin.setVisibility(View.VISIBLE);
                            } else {
                                fl_yin.setVisibility(View.GONE);
                            }
                        } else {
                            fl_yin.setVisibility(View.GONE);
                        }

                        ImageView iv_community_image = holder.getView(R.id.iv_community_image);

                        GlideImgManager.glideLoader(getContext(), entity, iv_community_image, 1);
                    }

                    @Override
                    public int getLayoutViewId(int viewType) {
                        return R.layout.item_community_image_layout;
                    }
                };
                rv_community_image.setAdapter(mImageAdapter);
            }


            @Override
            public int getLayoutViewId(int viewType) {
                return R.layout.item_community_type2;
            }
        };

        rv_data.setAdapter(mAdapter);

        mAdapter.setOnRecyclerViewItemClickListener(new CommonRecyclerViewAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                if (mList.get(position).getIzFee().equals("0")) {
                    startActivity(new Intent(getContext(), CommunityDetailsAc.class)
                            .putExtra("id", mList.get(position).getId()));
                } else {
                    //收费
                    dialogPay(
                            mList.get(position).getId(),
                            mList.get(position).getMoney());
                }
            }
        });
    }

    /**
     * 购买
     */
    private void dialogPay(String id, String money) {
        //1、使用Dialog、设置style
        final Dialog dialog = new Dialog(getContext(), R.style.DialogTheme);
        //2、设置布局
        View view = View.inflate(getContext(), R.layout.dialog_play_video, null);
        dialog.setContentView(view);

        TextView tv_money = view.findViewById(R.id.tv_money);
        tv_money.setText("￥" + money);

        TextView tv_over = view.findViewById(R.id.tv_over);

        ImageView iv_close = view.findViewById(R.id.iv_close);

        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        if (StringUt.isEmpty(over)) {
            tv_over.setText("￥0");
        } else {
            tv_over.setText("￥" + over);
        }

        TextView bt_play = view.findViewById(R.id.bt_play);

        bt_play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!StringUt.isEmpty(money) && !StringUt.isEmpty(over)) {
                    if (Double.valueOf(over) > Double.valueOf(money)) {
                        //钱够支付
                        purchaseVideo(id, money);
                        dialog.dismiss();
                    } else {
                        Toast.makeText(getContext(), "余额不足", Toast.LENGTH_SHORT).show();
                    }
                } else if (StringUt.isEmpty(over)) {
                    Toast.makeText(getContext(), "余额不足", Toast.LENGTH_SHORT).show();
                }
            }
        });

        Window window = dialog.getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置弹出动画
//        window.setWindowAnimations(R.style.main_menu_animStyle);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.show();

    }

    /**
     * 余额购买视频
     *
     * @param id
     * @param money
     */
    private void purchaseVideo(String id, String money) {
        dialogPass(id, money);
    }

    /**
     * 支付密码
     */
    private void dialogPass(String id, String money) {
        DynamicOrderBody dynamicOrderBody = new DynamicOrderBody();
        dynamicOrderBody.setDynamicId(id);
//        dynamicOrderBody.setMoney(money);

        final PayPassDialog dialog = new PayPassDialog(getContext());
        dialog.getPayViewPass()
                .setRandomNumber(true)
                .setPayClickListener(new PayPassView.OnPayClickListener() {
                    @Override
                    public void onPassFinish(String passContent) {
                        //6位输入完成回调
                        Log.d("ret", "joker  输入的密码===" + passContent);
                        dynamicOrderBody.setWalletPassword(passContent);
                        ApiUtil.getVideoApi().dynamicOrder(SPUtil.getToken(getContext()),
                                dynamicOrderBody).observe(getViewLifecycleOwner(), new BaseObserver<>(new BaseObserverCallBack<ApiResponse<BaseBean>>() {
                            @Override
                            public void onSuccess(ApiResponse<BaseBean> data) {
                                if (null != data) {
                                    if (null != data.getData()) {
                                        if (data.getData().getCode() == 0) {
                                            Toast.makeText(getContext(), "购买成功", Toast.LENGTH_SHORT).show();
                                            dialog.dismiss();
                                            page = 1;
                                            getDynamicList();
                                            queryById();
                                        } else {
                                            NullTokenUtils.isNullToken(data.getData().getCode(), data.getData().getMsg());
                                        }
                                    }
                                }
                            }
                        }));
                    }

                    @Override
                    public void onPayClose() {
                        dialog.dismiss();
                        //关闭弹框
                    }

                    @Override
                    public void onPayForget() {
                        dialog.dismiss();
                        //点击忘记密码回调
                    }
                });

    }


    @OnClick({R.id.ll_attention, R.id.ll_recommend, R.id.ll_same_city, R.id.ll_feezone
            , R.id.iv_community_dialog})
    public void setOnClick(View view) {
        switch (view.getId()) {
            //关注
            case R.id.ll_attention:
                setTextCheck(0);
                page = 1;
                isSelf = "1";
                isTj = "";
                city = "";
                izFee = "";
                getDynamicList();
                break;
            //推荐
            case R.id.ll_recommend:
                setTextCheck(1);
                page = 1;
                isSelf = "";
                isTj = "1";
                city = "";
                izFee = "";
                getDynamicList();
                break;
            //同城
            case R.id.ll_same_city:
                setTextCheck(2);
                //启动定位
                page = 1;
                isSelf = "";
                isTj = "";
                izFee = "";
                mlocationClient.startLocation();
                break;
            //收费专区
            case R.id.ll_feezone:
                setTextCheck(3);
                page = 1;
                isSelf = "";
                isTj = "";
                izFee = "1";
                mlocationClient.startLocation();
                break;
            //更多选项
            case R.id.iv_community_dialog:
                dialog();
                break;
        }
    }

    /**
     * 更多选项 发布图文，发布文章
     */
    private void dialog() {
        //创建并显示popWindow
        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_community_gd, null);

        CustomPopWindow mCustomPopWindow = new CustomPopWindow.PopupWindowBuilder(getContext())
                .setView(contentView)
                .enableBackgroundDark(true) //弹出popWindow时，背景是否变暗
                .setBgDarkAlpha(0.7f) // 控制亮度
                .create()
                .showAsDropDown(iv_community_dialog, 0, 20);

        TextView tv_content1 = contentView.findViewById(R.id.tv_content1);
        TextView tv_content2 = contentView.findViewById(R.id.tv_content2);

        tv_content1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), ImageTextAc.class));
                mCustomPopWindow.dissmiss();
            }
        });
        tv_content2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), TextAc.class));
                mCustomPopWindow.dissmiss();
            }
        });

    }

    public void setTextCheck(int position) {
        for (int i = 0; i < textViewList.size(); i++) {
            if (i == position) {
                textViewList.get(position).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                textViewList.get(position).getPaint().setFakeBoldText(true);
                imageViewList.get(position).setVisibility(View.VISIBLE);
            } else {
                textViewList.get(i).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                textViewList.get(i).getPaint().setFakeBoldText(false);
                imageViewList.get(i).setVisibility(View.INVISIBLE);
            }
        }
    }

    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (amapLocation != null) {
            if (amapLocation.getErrorCode() == 0) {
                //定位成功回调信息，设置相关消息
                amapLocation.getLocationType();//获取当前定位结果来源，如网络定位结果，详见定位类型表
                city = amapLocation.getCity();
                Log.d("ret", "joker   城市==" + city);
                mlocationClient.stopLocation();
                getDynamicList();
            } else {
                //显示错误信息ErrCode是错误码，errInfo是错误信息，详见错误码表。
                Log.e("AmapError", "location Error, ErrCode:"
                        + amapLocation.getErrorCode() + ", errInfo:"
                        + amapLocation.getErrorInfo());
            }
        }
    }
}
